package com.test;

import java.io.IOException;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

@SuppressWarnings("unchecked")
public class MessageSchemaXML {

	public static void main(String[] args) {
		read("messageSchemaXml.xml");
		System.out.println("执行完毕！");
	}
	
	@SuppressWarnings("rawtypes")
	public static void read(String filename) {
		SAXBuilder saxb = new SAXBuilder();
		StringBuilder sb = new StringBuilder();
		try {
			Document dc = saxb.build(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename));
			Element root = dc.getRootElement();
			List<Element> classes = (List) root.getChildren();
			int i = 0;
			int j = 100;
			for (Element element : classes) {
				if (i == 0) {
					sb.append("<List>\n");
					sb.append("<Field tag=\"10792\" value=\""+ j++ +"\">Flag</Field>\n");
				}else if (i == 1) {
					sb.append("<Field tag=\"11017\">" + element.getName() + "</Field>\n");
				}else if (i == 2) {
					sb.append("<Field tag=\"58\">" + element.getName() + "</Field>\n");
				}else if (i == 3) {
					sb.append("<Field tag=\"10994\">" + element.getName() + "</Field>\n");
					sb.append("</List>\n");
					i = -1;
				}
				i++;
			}
			System.out.println(sb);
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}